﻿

local moduleName = "RaidIcon"



----------------------------
--      Localization      --
----------------------------

local L = {
	[moduleName] = "Raid Icons",
}
if GetLocale() == "zhCN" then
	L[moduleName] = "团队图标"
elseif GetLocale() == "zhTW" then
	L[moduleName] = "團隊圖示"
end

----------------------------------
--      Local Declaration      --
----------------------------------



----------------------------------
--      Module Declaration      --
----------------------------------

local plugin = BunchOfBars:NewModule(moduleName)

plugin.revision = tonumber(("$Revision: 40 $"):match("%d+"))

plugin.options = {
	name = L[moduleName],
	args = {
	}
}
plugin.defaultDB = {
	profile = {
		iconsize = 14,
		style = {
			position = "TOPRIGHT",
			xof = -4,
			yof = 2,
		}
	}
}
plugin.head = {
	core = true
}
plugin.moduletype = "icon"

----------------------------------
--      Module Functions        --
----------------------------------

function plugin:OnEnable()
	self:RegisterEvent("RAID_TARGET_UPDATE", "UpdateAll")
end


function plugin:OnCreate(frame)
	local icon = frame:CreateTexture(nil, "OVERLAY")
	icon:SetHeight(14)
	icon:SetWidth(14)
	icon:SetTexture("Interface\\TargetingFrame\\UI-RaidTargetingIcons")
	icon:ClearAllPoints()
--	icon:SetPoint("CENTER", frame, "TOPRIGHT", -4, -2)
	icon:Hide()
	
	return icon
end

function plugin:OnUpdate(frame)
	local i = GetRaidTargetIndex(frame.unit)
	local icon = frame.parts[moduleName]
	if i then
		SetRaidTargetIconTexture(icon, i)
		icon:Show()
	else
		icon:Hide()
	end
end



----------------------------------
--      Option Handlers         --
----------------------------------
function plugin:SetIconSize()
	self:UpdateAllWith(function(frame)
		frame.parts[moduleName]:SetHeight(self.db.profile.iconsize)
		frame.parts[moduleName]:SetWidth(self.db.profile.iconsize)
	end)
end